package com.xrz.sxm.aj.activity;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.xrz.sxm.aj.base.BaseAct;
import com.xrz.sxm.aj.utils.ScreenUtil;
import com.xrz.sxm.aj.utils.VersonUtil;

public class AboutActivity extends BaseAct {
	@ViewInject(R.id.rg)
	private RadioGroup radiogroup;
	@ViewInject(R.id.pager_weight_rb1)
	private RadioButton rb1;
	@ViewInject(R.id.pager_weight_rb0)
	private RadioButton rb0;
	@ViewInject(R.id.pager_weight_rb2)
	private RadioButton rb2;
	@ViewInject(R.id.pager_weight_rb3)
	private RadioButton rb3;
	@ViewInject(R.id.pager_weight_rb5)
	private RadioButton rb5;
	@ViewInject(R.id.tabhost)
	private TabHost mTabHost;
	private LocalActivityManager mActivityManager;
	private View TabWeight;
	private int View_width, View_height;

	/** 标题栏高度 */
	private int m_TitleBar_hight;
	/** tab高度 */
	private int m_Tab_Hight;

	@Override
	protected int setView() {
		return R.layout.layout_about;
	}

	@Override
	protected void init() {
		TabWeight = LayoutInflater.from(this).inflate(R.layout.tabweight, null);
		int w = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		int h = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		TabWeight.measure(w, h);
		View_width = TabWeight.getMeasuredWidth();
		View_height = TabWeight.getMeasuredHeight();
		ScreenUtil.getInstant().putViewScreen(this, View_width, View_height);
		mActivityManager = new LocalActivityManager(this, true);
		mActivityManager.dispatchCreate(GetBundle());
		mTabHost.setup(mActivityManager);
		mTabHost.setup();
		getTitlteBarHight();
		mTabHost.addTab(mTabHost
				.newTabSpec("1")
				.setIndicator("1")
				.setContent(
						new Intent(this, About_ChanpinActivity.class).putExtra(
								"data", m_TitleBar_hight + m_Tab_Hight)));
		mTabHost.addTab(mTabHost.newTabSpec("2").setIndicator("2")
				.setContent(new Intent(this, About_jiajuActivity.class)));

		mTabHost.addTab(mTabHost.newTabSpec("3").setIndicator("3")
				.setContent(new Intent(this, About_QiyeActivity.class)));
		mTabHost.addTab(mTabHost
				.newTabSpec("4")
				.setIndicator("4")
				.setContent(new Intent(this, About_LianxiFangshiActivity.class)));
		mTabHost.addTab(mTabHost.newTabSpec("5").setIndicator("5")
				.setContent(new Intent(this, About_YijianFankuiActivity.class)));
		rb1.setChecked(true);
		radiogroup.setOnCheckedChangeListener(lis);
		rightBtn.setVisibility(View.VISIBLE);
		rightBtn.setText("版本");
		rightBtn.setBackgroundResource(R.drawable.selector_version_btn);
		rightBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String version = VersonUtil.getVisionName(AboutActivity.this);
				showMessageDialog("版本信息", version);
			}
		});
	}

	/**
	 * 获取顶部菜单和Tab的高度
	 */
	private void getTitlteBarHight() {
		int w = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		int h = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		topRela.measure(w, h);
		radiogroup.measure(w, h);
		m_TitleBar_hight = topRela.getMeasuredHeight();
		m_Tab_Hight = radiogroup.getMeasuredHeight();
		Log.e(TAG, m_TitleBar_hight + "     " + m_Tab_Hight);
	}

	private OnCheckedChangeListener lis = new OnCheckedChangeListener() {

		public void onCheckedChanged(RadioGroup arg0, int arg1) {
			switch (arg1) {
				case R.id.pager_weight_rb1:
					rb1.setChecked(true);
					mTabHost.setCurrentTab(0);
					break;
				case R.id.pager_weight_rb0:
					rb0.setChecked(true);
					mTabHost.setCurrentTab(1);
					break;
				case R.id.pager_weight_rb2:
					rb2.setChecked(true);
					mTabHost.setCurrentTab(2);
					break;
				case R.id.pager_weight_rb3:
					rb3.setChecked(true);
					mTabHost.setCurrentTab(3);
					break;
				case R.id.pager_weight_rb5:
					rb5.setChecked(true);
					mTabHost.setCurrentTab(4);
					break;
			}
		}
	};

	@Override
	protected String setTopTitle() {
		return "关于艾邻";
	}
}
